package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.DataDetail;
import cn.wolfcode.crm.mapper.DataDetailMapper;
import cn.wolfcode.crm.query.impl.DataDetailQuery;
import cn.wolfcode.crm.service.IDataDetailService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DataDetailServiceImpl implements IDataDetailService {

    @Autowired
    DataDetailMapper mapper;

    public void saveOrUpdate(DataDetail record) {
        if (record.getId() == null) {
            mapper.insert(record);
        } else {
            mapper.updateByPrimaryKey(record);
        }
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public PageResult query(DataDetailQuery qo) {
        int rows = mapper.queryForCount(qo);
        if (rows == 0) {
            return new PageResult(rows, Collections.EMPTY_LIST);
        }
        List<?> result = mapper.queryForList(qo);
        return new PageResult(rows,result);
    }

    public List<DataDetail> selectAllByCus(String sn) {
        return mapper.selectAllByCus(sn);
    }
}
